function addRouter(router, list) {
  if (!Array.isArray(list) || list.length == 0) return;
  let arr = deepFilter(list);
  dataChange(arr);
  arr.forEach((item) => {
    router.addRoute("layout", item);
  });
}
// 添加组件
function dataChange(arr) {
  if (!Array.isArray(arr) || arr.length == 0) return;
  arr.forEach((item) => {
    item.path = item.url;
    if (item.component) {
      item.component = viteComponent[`../views${item.component}.vue`];
    }
    if (item.children) {
      dataChange(item.children);
    }
  });
}

// 筛选数组
function deepFilter(list) {
  return list.filter((item) => {
    if (item.children) {
      item.children = deepFilter(item.children);
    }
    return item.menu_type !== "B";
  });
}

const viteComponent = import.meta.glob("../views/**/*.vue");
//

export { addRouter };
